<?php

class Kenh14 {

    var $links = array();
    var $title = "";
    var $intro = "";
    var $content = "";
    var $imgurl = "";

    function Init() {
        $this->title = "";
        $this->intro = "";
        $this->content = "";
        $this->imageurl = "";
    }

    function GetLink($link) {       
        $link = trim($link);
        if (getFileExt($link) == 'rss') {
            $rss = RssReader($link);

            for ($i = 0; $i < sizeof($rss); $i++)
                array_push($this->links, $rss[$i]['link']);
        } else {
            $document = FetchDataString($link);
            if (preg_match('/<div id="ctl00_ContentPlaceHolder1_.*?" class=".*?">(.*?)<td class=\'TrangTruocSau\'>/s', $document, $regs))
                $document = $regs[1];

            if (!preg_match_all('/href=[\'"](.*?)["\']/', $document, $result, PREG_PATTERN_ORDER))
                return false;

            $n = sizeof($result[1]);

            for ($i = 0; $i < $n; $i++) {
                $flag = 0;
                for ($j = $i + 1; $j < $n; $j++)
                    if ($result[1][$j] == $result[1][$i])
                        $flag = 1;

                if ($flag == 0)
                    array_push($this->links, "http://kenh14.vn" . $result[1][$i]);
            }
        }

        return true;
    }

    function GetInfo($link) {
        $this->Init();

        $document = FetchDataString($link);

        if (!preg_match('%<span id="ctl00_ContentPlaceHolder1_ctl02_lblNews_Title" class="News_Detail_title" style="text-align: left">(.*?)</span>%s', $document, $regs))
            return false;

        $this->title = $regs[1];

        if (!preg_match('%<span id="ctl00_ContentPlaceHolder1_ctl02_lblNews_InitCont" class="quickView_Detail">(.*?)</span>%s', $document, $regs))
            return false;

        $this->intro = $regs[1];
		
		$document = TextBetween('<span id="ctl00_ContentPlaceHolder1_ctl02_lblNews_Content" class="Content">','<div class="o_f" style="padding: 10px;" align="center">',$document);

        if (preg_match('%<span id="ctl00_ContentPlaceHolder1_ctl02_lblNews_Content" class="Content">(.*?)</span>%s', $document, $regs))
            $this->content = $regs[1];
		else
	        $this->content = $document;
		


        if (!preg_match_all('%<img src=[\'"](http://.*?)[\'"].*?>%si', $this->content, $regs, PREG_PATTERN_ORDER))
            $this->imgurl = "";
        else
            $this->imgurl = $regs[1][0];



        return true;
    }

}

?>
